package com.smart.service.impl;

import com.smart.pojo.Product;
import com.smart.resp.EchartsData;
import com.smart.resp.PopularProduct;
import com.smart.service.IProduceService;
import com.smart.service.IProductService;
import com.smart.service.ISalesOrderService;
import com.smart.service.IStatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IStatisticServiceImpl implements IStatisticService {

    @Autowired
    ISalesOrderService salesOrderService;

    @Autowired
    IProductService productService;

    @Autowired
    IProduceService produceService;

    @Override
    public Map<String, Object> getBusinessData() {
        Map<String, Object> map = new HashMap<>();
        //本月订单数
        int currentCount = salesOrderService.getCurrentOrders();
        map.put("currentOrders", currentCount);
        //总订单数
        int count = salesOrderService.count();
        map.put("totalOrders", count);

        //本月成交额
        BigDecimal currentTurnover = salesOrderService.getCurrentTurnover();
        map.put("currentTurnover", currentTurnover);
        //总成交额
        BigDecimal totalTurnover = salesOrderService.getTotalTurnover();
        map.put("totalTurnover", totalTurnover);

        //本周畅销
        PopularProduct weekPopularProduct = salesOrderService.getWeekPopularProduct();
        map.put("weekPopularProduct", weekPopularProduct);

        //年度畅销
        PopularProduct yearPopularProduct = salesOrderService.getYearPopularProduct();
        map.put("yearPopularProduct", yearPopularProduct);
        return map;
    }

    @Override
    public Map<String, Object> getInventoryAndTurnoverData() {
        Map<String, Object> map = new HashMap<>();
        List<EchartsData> inventoryList = productService.getInventoryData();
        map.put("inventoryList", inventoryList);

        List<EchartsData> turnoverList = salesOrderService.getTurnoverData();
        map.put("turnoverList", turnoverList);
        return map;
    }

    @Override
    public Map<String, Object> getSalesAndProfitAndPlanData() {
        Map<String, Object> map = new HashMap<>();
        List<EchartsData> salesList = salesOrderService.getSalesData();
        map.put("salesList", salesList);

        List<EchartsData> profitList = salesOrderService.getProfitData();
        map.put("profitList", profitList);

        List<EchartsData> planList = produceService.getPlanData();
        map.put("planList", planList);

        return map;
    }
}
